package com.ruoyi.teacher.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teacher.domain.TBook;
import com.ruoyi.teacher.service.ITBookService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 著作信息集Controller
 *
 * @author xiangzy
 * @date 2022-05-10
 */
@Api(tags = "著作管理")
@RestController
@RequestMapping("/teacher/book")
public class TBookController extends BaseController
{
    @Autowired
    private ITBookService tBookService;

    /**
     * 查询著作信息集列表
     */
    @ApiOperation(value = "查询著作信息集列表")
    @PreAuthorize("@ss.hasPermi('teacher:book:list')")
    @GetMapping("/list")
    public TableDataInfo list(TBook tBook)
    {
        startPage();
        List<TBook> list = tBookService.selectTBookList(tBook);
        return getDataTable(list);
    }

    /**
     * 导出著作信息集列表
     */
    @ApiOperation(value = "导出著作信息集列表")
    @PreAuthorize("@ss.hasPermi('teacher:book:export')")
    @Log(title = "著作信息集", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TBook tBook)
    {
        List<TBook> list = tBookService.selectTBookList(tBook);
        ExcelUtil<TBook> util = new ExcelUtil<TBook>(TBook.class);
        return util.exportExcel(list, "book");
    }

    /**
     * 获取著作信息集详细信息
     */
    @ApiOperation(value = "获取著作信息集详细信息")
    @PreAuthorize("@ss.hasPermi('teacher:book:query')")
    @GetMapping(value = "/{recordid}")
    public AjaxResult getInfo(@PathVariable("recordid") Long recordid)
    {
        return AjaxResult.success(tBookService.selectTBookById(recordid));
    }

    /**
     * 新增著作信息集
     */
    @PreAuthorize("@ss.hasPermi('teacher:book:add')")
    @Log(title = "著作信息集", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TBook tBook)
    {
        return toAjax(tBookService.insertTBook(tBook));
    }

    /**
     * 修改著作信息集
     */
    @PreAuthorize("@ss.hasPermi('teacher:book:edit')")
    @Log(title = "著作信息集", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TBook tBook)
    {
        return toAjax(tBookService.updateTBook(tBook));
    }

    /**
     * 删除著作信息集
     */
    @PreAuthorize("@ss.hasPermi('teacher:book:remove')")
    @Log(title = "著作信息集", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordids}")
    public AjaxResult remove(@PathVariable Long[] recordids)
    {
        return toAjax(tBookService.deleteTBookByIds(recordids));
    }
}
